package com.zjsru.controller;

import com.alibaba.cloud.nacos.discovery.NacosServiceDiscovery;
import com.alibaba.nacos.api.exception.NacosException;
import com.zjsru.pojo.Order;
import com.zjsru.pojo.User;
import com.zjsru.service.OrderService;
import com.zjsru.service.UserClient;
import org.mybatis.logging.Logger;
import org.mybatis.logging.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

/*@Controller
@ResponseBody*/
@RestController
@RequestMapping("/order")
public class OrderController {
    private static final Logger logger = LoggerFactory.getLogger(OrderController.class);
    @Autowired
    OrderService orderService;

    @Autowired
    UserClient userclient ;
    @GetMapping("/{orderId}")
    public Order queryOrderByUserId(@PathVariable("orderId") Long orderId) throws NacosException {
        // 根据id查询订单并返回
        Order order = orderService.queryOrderById(orderId);
        User user = userclient.getUserById(order.getUser_Id());
        order.setUser(user);
        return order;

    }
}
